<template>
  <div>
    <van-nav-bar
      title="更新昵称"
      left-text="取消"
      right-text="保存"
      @click-right="onClickRight"
      @click-left="onClickLeft"
    />
    <van-field
      v-model="message"
      rows="2"
      autosize
      type="textarea"
      maxlength="11"
      placeholder="请输入昵称"
      show-word-limit
    />
  </div>
</template>

<script>
import { changeInfo } from '@/api'
export default {
  props: {
    usae: {
      type: String,
      require: true
    }
  },
  data() {
    return {
      message: this.usae
    }
  },
  methods: {
    onClickLeft() {
      this.$emit('change')
    },
    async onClickRight() {
      try {
        this.$toast.loading({
          message: '更新中',
          forbidClick: true
        })
        await changeInfo({ name: this.message })
        this.$emit('update:usae', this.message)
        this.$toast.success('更新昵称成功')
        this.$emit('change')
      } catch (error) {}
    }
  }
}
</script>

<style></style>
